switch: Remove in_switch flag
authorTimm Bäder <mail@baedert.org>
Sat, 17 Jun 2017 12:18:14 +0000 (14:18 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 20 Jul 2017 01:27:14 +0000 (21:27 -0400)
It's pretty simple and less code to just check whether the gesture
coords are inside the widget at the one place where we actually used the
flag.

gtk/gtkswitch.c

index de8b4c6be646e043c88b6ec34c9346104e55811c..db6fd478093d37e8f038c75f7895bdcf45afa741 100644 (file)
@@ -85,7 +85,6 @@ struct _GtkSwitchPrivate
 
   guint state                 : 1;
   guint is_active             : 1;
-  guint in_switch             : 1;
 
   GtkWidget *on_label;
   GtkWidget *off_label;
@@ -209,12 +208,14 @@ gtk_switch_multipress_gesture_released (GtkGestureMultiPress *gesture,
                                         gdouble               y,
                                         GtkSwitch            *sw)
 {
-  GtkSwitchPrivate *priv = sw->priv;
   GdkEventSequence *sequence;
+  GdkRectangle own_alloc;
 
   sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
 
-  if (priv->in_switch &&
+  gtk_widget_get_own_allocation (GTK_WIDGET (sw), &own_alloc);
+
+  if (gdk_rectangle_contains_point (&own_alloc, x, y) &&
       gtk_gesture_handles_sequence (GTK_GESTURE (gesture), sequence))
     gtk_switch_begin_toggle_animation (sw);
 }
@@ -277,28 +278,6 @@ gtk_switch_pan_gesture_drag_end (GtkGestureDrag *gesture,
   gtk_widget_queue_allocate (GTK_WIDGET (sw));
 }
 
-static gboolean
-gtk_switch_enter (GtkWidget        *widget,
-                  GdkEventCrossing *event)
-{
-  GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
-
-  priv->in_switch = TRUE;
-
-  return FALSE;
-}
-
-static gboolean
-gtk_switch_leave (GtkWidget        *widget,
-                  GdkEventCrossing *event)
-{
-  GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
-
-  priv->in_switch = FALSE;
-
-  return FALSE;
-}
-
 static void
 gtk_switch_activate (GtkSwitch *sw)
 {
@@ -593,8 +572,6 @@ gtk_switch_class_init (GtkSwitchClass *klass)
   widget_class->measure = gtk_switch_measure;
   widget_class->size_allocate = gtk_switch_size_allocate;
   widget_class->snapshot = gtk_switch_snapshot;
-  widget_class->enter_notify_event = gtk_switch_enter;
-  widget_class->leave_notify_event = gtk_switch_leave;
 
   klass->activate = gtk_switch_activate;
   klass->state_set = state_set;